﻿using NLog;
using System;

namespace PlatformNetCore.Common.Helper
{
    public class LogHelper
    {
        private static ILogger logger = LogManager.GetLogger(typeof(LogHelper).Name);
        private static ILogger logError = LogManager.GetLogger("LoggerError");
        /// <summary>
        /// 正常日记
        /// </summary>
        /// <param name="message"></param>
        public static void Info(string message)
        {
            if (logger.IsInfoEnabled)
            {
                logger.Info(message);
            }
        }
        /// <summary>
        /// 正常日记
        /// </summary>
        /// <param name="message"></param>
        public static void Info(string title, string message)
        {
            if (logger.IsInfoEnabled)
            {
                logger.Info(string.Format("{0}：{1}", title, message));
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="t"></param>
        /// <param name="msg"></param>
        public static void WriteLog(Type t, string msg, string repository)
        {
            logger = LogManager.GetLogger(repository);
            logger.Info(msg);
        }

        /// <summary>
        /// 警告日记
        /// </summary>
        /// <param name="message"></param>
        public static void Warn(string message)
        {
            if (logger.IsWarnEnabled)
            {
                logger.Warn(message);
            }
        }

        /// <summary>
        /// 警告日记
        /// </summary>
        /// <param name="message"></param>
        public static void Warn(string title, string message)
        {
            if (logger.IsWarnEnabled)
            {
                logger.Warn(string.Format("{0}：{1}", title, message));
            }
        }

        /// <summary>
        /// 警告日记
        /// </summary>
        /// <param name="message"></param>
        public static void Warn(Exception ex)
        {
            if (logger.IsWarnEnabled)
            {
                logger.Warn(ex);
            }
        }
        /// <summary>
        /// 错误日记
        /// </summary>
        /// <param name="message"></param>
        public static void Error(string message)
        {
            if (logError.IsErrorEnabled)
            {
                logError.Error(message);
            }
        }
        /// <summary>
        /// 错误日记
        /// </summary>
        /// <param name="message"></param>
        public static void Error(string title, string message)
        {
            if (logError.IsErrorEnabled)
            {
                logError.Error(string.Format("{0}：{1}", title, message));
            }
        }
        /// <summary>
        /// 错误日记
        /// </summary>
        /// <param name="message"></param>
        public static void Error(Exception ex)
        {
            if (logError.IsErrorEnabled)
            {
                logError.Error(ex);
            }
        }
        /// <summary>
        /// Trace日记
        /// </summary>
        /// <param name="message"></param>
        public static void Trace(string message)
        {
            if (logger.IsTraceEnabled)
            {
                logger.Trace(message);
            }
        }
        /// <summary>
        /// Trace日记
        /// </summary>
        /// <param name="message"></param>
        public static void Trace(string title, string message)
        {
            if (logger.IsTraceEnabled)
            {
                logger.Trace(string.Format("{0}：{1}", title, message));
            }
        }
        /// <summary>
        /// Trace日记
        /// </summary>
        /// <param name="message"></param>
        public static void Trace(Exception ex)
        {
            if (logger.IsTraceEnabled)
            {
                logger.Trace(ex);
            }
        }
    }
}
